{webcontrol type='LoadJsCss' src="Resource/Script/jquery.json.js"}
<script language="javascript">
var controller = '{$smarty.get.controller}';
var rukuId = '{$smarty.get.id}';
var kuwei='';
{literal}
$(function(){
  //因为需要使用ret作为回调函数的参数，所以需要使用bind,
  //选择订单后，明细栏中显示订单明细情况
  $('[name="planIdA"]').data('onSel',function(ret){
    var trs = $('.trRow');
    var len = trs.length; 
    var tpl = trs.eq(0).clone(true);
    var pNode = trs.parent();
    // console.log('ss',ret);
    var  planArr = [];
    if(ret.id){ //双击情况(单选)
        planArr.push(ret.id);
    }else{      //多选情况
        for(var key in ret){    
           planArr.push(ret[key].id);//取得value      
        } 
    }
      
    //插入订单明细的情况
    var url='?controller=Chengpin_Dye_CpMdZyCk&action=GetMinxiByPlanId';
    var param={'planId':planArr};
    // debugger;
    $.post(url,param,function(ret){
      // debugger;
      console.log('sas',ret);
      if(!ret.success) {
        alert(ret.msg);
        return;
      }
      var json = ret.res;
      if(!json) {
        alert('未发现数据集');
        return;
      }
      for(var i=0;trs[i];i++) {
        var id = $('[name="gangId[]"]',trs[i]);
        if(id.val()!='') continue;
        trs.eq(i).remove();
      }
      for(var i=0;json[i];i++) {
        var nt = tpl.clone(true); 
        $('input,select',nt).val(''); 

        //为控件赋值
        $('[name="orderCode[]"]',nt).val(json[i].orderCode);
        $('[name="vatNum[]"]',nt).val(json[i].vatNum);
        $('[name="proName[]"]',nt).val(json[i].proName);
        $('[name="color[]"]',nt).val(json[i].color);
        $('[name="colorNum[]"]',nt).val(json[i].colorNum);
        $('[name="gangId[]"]',nt).val(json[i].id);
        pNode.append(nt);
      }
      tpl = null;
      return;
    },'json');  
    
  });
    /**
    * 选择按钮单机事件
    * 打开选择界面
    */
    $('[name="btnMadan"]').click(function(){
        var tr = $(this).parents('.trRow');
        var ganghao=$('[name="vatNum[]"]',tr).val();
        var wareId=$('[name="wareId[]"]',tr).val();
        var gangId=$('[name="gangId[]"]',tr).val();
        var ord2proId=$('[name="ord2proId[]"]',tr).val();
        var dabaoCode = $('[name="dabaoCode[]"]',tr).val();
        var chukuId = $('[name="id[]"]',tr).val();

        var index=$('[name="btnMadan"]').index(this);
        var url="?controller="+controller+"&action=ViewChoose&index="+index+'&wareId='+wareId+'&gangId='+gangId+'&ord2proId='+ord2proId+'&ganghao='+encodeURIComponent(ganghao)+'&dabaoCode='+dabaoCode+'&chukuId='+chukuId;
        var _this = this;
        choose_layer = $.layer({
              type: 2,
              shade: [1],
              fix: false,
              title: '选择',
              maxmin: true,
              iframe: {src : url},
              // border:false,
              area: ['1024px' , '640px'],
              close: function(index){//关闭时触发

              },
              //回调函数定义
              callback:function(index,ret) {
                console.log(ret);
                var cnt=parseFloat(ret.cnt).toFixed(2);
                var cntL=parseFloat(ret.cntL).toFixed(2);
                // $(_this).text('码单-净重:'+parseFloat(ret.cntDz||0).toFixed(2));
                $('[name="Madan[]"]',tr).val(ret.cId);
                $('[name="cnt[]"]',tr).val(cnt);
                $('[name="cntL[]"]',tr).val(cntL);
                $('[name="cntJuan[]"]',tr).val(ret.cntJuan);
                $('[name="cntDz[]"]',tr).val(ret.cntDz);
                $('[name="cntTongzi[]"]',tr).val(ret.cntTongzi);
            }
        });
    })

});

function tb_remove(){
    layer.close(choose_layer); //执行关闭
}
$('[name="planIdA"]').data('beforeOpen',function(url){
    var gangId=$('[name="gangId[]"]');
    var gangArr = [];
    for(var i=0;i<gangId.length;i++){
        gangArr.push(gangId[i].value);
    }
    gangArr = gangArr.join(',');
    url+="&gangId="+gangArr;
    console.log('uu',url);
    return url;
});
function beforeSubmit(){
  var cnt=document.getElementsByName("cnt[]");
  var memo=document.getElementsByName("memo[]");
  var cntArr = [];
  var memoArr = [];
  for(var i=0;i<cnt.length;i++){
    cntArr.push(cnt[i].value);
  }
  for(var j=0;j<memo.length;j++){
    memoArr.push(memo[j].value);
  }
    var tt = '';
  $.ajax({
     type:'POST',
     data:{jingKg:cntArr,memo:memoArr},
     dataType:'json',
     async:false, 
     url:'?controller=Chengpin_Dye_Cpck&action=CheckMemo',
     success:function(ret){
        if(!ret.succ){
           tt = 1;
           alert(ret.msg);
          return false;
        }else{
           tt = 2;
           return true;
        }
     }
  });
  if(tt==1)
  {
    return false;
  }else{
     return true;
  }
}

{/literal}
</script>